<script setup lang="ts">
import { ref, watch } from "vue";
import ReCol from "@/components/ReCol";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import { usePublicHooks } from './hooks'

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    name: "",
    type: null,
    x: null,
    y: null,
    sort: null,
    status: 1,
    note: "",
    mapid: null,
    parentid: undefined,
  }),
  stationTypes: [],
  mapTypes: [],
  stationSelect: []
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);
const stationTypes = ref(props.stationTypes);
const mapTypes = ref(props.mapTypes);
const stationSelect = ref(props.stationSelect);

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form ref="ruleFormRef" :model="newFormInline" :rules="formRules" label-width="82px">
    <el-row :gutter="30">
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="站点名称" prop="name">
          <el-input v-model="newFormInline.name" clearable placeholder="请输入站点名称" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="类型" prop="type">
          <el-select v-model="newFormInline.type" placeholder="请选择类型" style="width:100%">
            <el-option v-for="item in stationTypes" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="X轴" prop="x">
          <el-input-number v-model="newFormInline.x" :precision="3" controls-position="right" placeholder="请输入X轴" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="Y轴" prop="y">
          <el-input-number v-model="newFormInline.y" :precision="3" controls-position="right" placeholder="请输入Y轴" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="排序" prop="sort">
          <el-input-number v-model="newFormInline.sort" controls-position="right" placeholder="请输入排序" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="状态" prop="status">
          <el-select v-model="newFormInline.status" clearable placeholder="请选择状态" style="width:100%">
            <el-option label="禁用" :value="0" />
            <el-option label="启用" :value="1" />
            <el-option label="锁定" :value="2" />
          </el-select>
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="所属地图" prop="mapid">
          <el-select v-model="newFormInline.mapid" placeholder="请选择所属地图" style="width:100%">
            <el-option v-for="item in mapTypes" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="总图站点" prop="parentid">
          <el-select v-model="newFormInline.parentid" placeholder="请选择总图站点" style="width:100%">
            <el-option v-for="item in stationSelect" :key="item.stationid" :label="item.stationname"
              :value="item.stationid" />
          </el-select>
        </el-form-item>
      </re-col>
      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="备注" prop="note">
          <el-input v-model="newFormInline.note" clearable placeholder="请输入备注" type="textarea" />
        </el-form-item>
      </re-col>
    </el-row>
  </el-form>
</template>

<style lang="scss" scoped>
.el-radio {
  margin-right: 16px;
}
</style>
